package net.cloudsun.tree;

import java.util.List;
import java.util.function.Consumer;

/**
 * @author Ryan
 * @since
 */
public interface Node<T> {
    T getValue();
    Node<T> getParent();
    <N extends Node<T>> List<N> getChildren();

    default Node<T> getRoot() {
        Node<T> p = this;
        while (p.getParent()!=null) {
            p = p.getParent();
        }
        return p;
    }

    default void listParent(Consumer<Node<T>> o) {
        Node<T> p = this;
        while (p.getParent()!=null) {
            o.accept(p);
            p = p.getParent();
        }
    }
}
